package edu.utexas.mapreduce;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class MapTask extends Task {

	private InputBlock input;
	
	MapTask(int id, InputBlock input) {
		super(id);
		this.input = input;
	}
	
	InputStream getInputStream() throws IOException {
		// Read the whole block to memory
		byte[] inputData = new byte[(int) (input.endOffset - input.startOffset)];
		FileInputStream fileIS = new FileInputStream(input.fileName);
		fileIS.skip(input.startOffset);
		fileIS.read(inputData);
		fileIS.close();
		// return a stream for the block
		return new ByteArrayInputStream(inputData);
	}
	
	String getFileName() {
		return input.fileName;
	}
}
